<template>
	<view>
		<!-- 搜索 -->
		<view class="search flex justify-center align-center">
			<view class="search-box">
				<u-search placeholder="搜索员工名称/电话" search-icon-color="#000000" shape="square" :show-action="false"
					v-model="search" @change="searchs()"></u-search>
			</view>
		</view>
		<!-- 状态切换 -->
		<!-- <view class="select flex">
			<view class="select-item flex justify-center align-center" :style="current==index?'background:#F2F5FF':''"
				@click="change(index)" v-for="(item,index) in select" :key="index">
				{{item}}
			</view>
		</view> -->
		<!-- 员工列表 -->
		<view class="list flex flex-wrap justify-center">
			<view class="list-box-item " v-for="(item,index) in list" :key="index">
				<view class="list-box-item-l flex align-center">
					<image :src="item.avatar?item.avatar:'../../static/logo.png'"></image>
					<view class="">
						<view class="info">
							<span>{{item.userName}}</span>
							<text>{{item.phone}}</text>
						</view>
					</view>
				</view>
				<view style="width: 100%;height: 1rpx;background: #E4E1E6;margin: 30upx 0;"></view>
				<view class="flex">
					<view style="width: 25%;text-align: center;" @click="getStaffUser(item.userId)">
						<image src="../static/weizhi.png" style="width: 34rpx;height: 40rpx;"></image>
						<view>当前位置</view>
					</view>
					<view style="width: 25%;text-align: center;" @click="StaffUser(item)">
						<image src="../static/shuju.png" style="width: 38rpx;height: 40rpx;"></image>
						<view>他的数据</view>
					</view>
					<view style="width: 25%;text-align: center;" @click="paidan(item)">
						<image src="../static/renwu.png" style="width: 36rpx;height: 38rpx;"></image>
						<view>他的派单</view>
					</view>
					<view style="width: 25%;text-align: center;" @click="deteStaffUser(item)">
						<image src="../static/tichu.png" style="width: 38rpx;height: 38rpx;"></image>
						<view>踢出</view>
					</view>
				</view>
			</view>
		</view>

		<!-- 底部新增按钮 -->
		<view class="addWork flex justify-center">
			<view class="addWork-box flex justify-center align-center" @click="gotoAdd()">
				添加员工
			</view>
		</view>

		<empty v-if="list.length==0"></empty>
		<!-- <empty v-if="list.length==0&&current==1"></empty> -->
	</view>
</template>

<script>
	import empty from '@/components/empty.vue'
	export default {
		components: {
			empty
		},
		data() {
			return {
				search: '',
				select: ['全部员工', '被踢出员工'],
				current: 0,
				list: [],
				page: 1,
				limit: 10,
			}
		},
		onLoad() {

		},
		onShow() {
			this.getorderlist()

		},
		methods: {
			//搜索
			searchs(){
				this.page = 1
				this.getorderlist()
			},
			paidan(e){
				uni.navigateTo({
					url:'/work/index/order?companyId='+e.userId
				})
			},
			change(index) {
				this.current = index
				if (this.current == 0) {
					this.page = 1
					this.getorderlist()
				}
			}, //新增员工
			gotoAdd() {
				uni.navigateTo({
					url: '/work/addWork/addWork'
				})
			},
			//派单数据
			StaffUser(e){
				uni.navigateTo({
					url:'/work/statistics/statistics?userId='+e.userId
				})
			},
			getorderlist() {
				let data = {
					page: this.page,
					limit: this.limit,
					phoneAndUserName: this.search,
					companyId:uni.getStorageSync('userId')
				}
				this.$Request.get("/app/user/selectUserList", data).then(res => {
					if (res.code == 0) {
						if (this.page == 1) {
							this.list = res.data.list
						} else {
							this.list = [...this.list, ...res.data.list]
						}
					}
					
					uni.stopPullDownRefresh();
				});
			},
			deteStaffUser(e){ //踢出员工
				let that = this
				uni.showModal({
					title: '提示',
					content: '确定踢出？',
					success: function(res) {
						if (res.confirm) {
							let data={
								byUserId:e.userId
							}
						that.$Request.post("/app/user/adminExitCompany", data).then(res => {
							if (res.code == 0) {
								uni.showToast({
									title:'踢出成功',
									icon:'none'
								})
								that.page=1
								that.getorderlist()
							}else{
								that.$queue.showToast(res.msg)
							}
						});
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			//获取员工信息
			getStaffUser(StaffUserId) {
				let data = {
					userId: StaffUserId,
				}
				this.$Request.get("/app/user/selectStaffUser", data).then(res => {
					if (res.code == 0) {
						this.$Request.get("/app/Login/selectAddress?lat=" + res.data.latitude + '&lng=' + res.data
							.longitude).then(ret => {
							if (ret.code == 0) {
								this.bindGps(res.data.latitude,res.data.longitude,ret.data)
							}
						});
					}
				});
			},
			// 一键导航
			bindGps(latitude, longitude, name) {
				uni.openLocation({
					latitude: latitude - 0, //要去的纬度-地址       
					longitude: longitude - 0, //要去的经度-地址
					name: name, //地址名称
					address: name, //详细地址名称
					success: function() {
						console.log('导航成功');
					},
					fail: function(error) {
						console.log(error)
					}
				});
			},

		},
		onReachBottom: function() {
			this.page = this.page + 1;
			this.getorderlist()
		},
		onPullDownRefresh: function() {
			this.page = 1;
			this.getorderlist()
		}
	}
</script>

<style lang="scss">
	page {
		background: #F5F5F5;
	}

	.search {
		width: 100%;
		height: 88rpx;
		background-color: #FFFFFF;
		position: fixed;
		/* #ifdef H5 */
		top: 80rpx;
		/* #endif */
		/* #ifndef H5 */
		top: 0rpx;
		/* #endif */
		z-index: 99;

		.search-box {
			width: 686rpx;
			height: 68rpx;

		}
	}

	.select {
		width: 100%;
		height: 88rpx;
		background-color: #FFFFFF;
		position: fixed;
		top: calc(88rpx * 2);
		z-index: 99;

		.select-item {
			width: 50%;
			height: 100%;
			color: #333333;
			font-size: 28rpx;

		}
	}

	.list {
		width: 100%;
		height: auto;
		margin-top: 106rpx;
		padding-bottom: 150rpx;

		.list-box-item {
			width: 94%;
			// height: 148rpx;
			border-radius: 24rpx;
			background-color: #FFFFFF;
			margin-bottom: 30rpx;
			padding: 30upx 0;
		}

		.list-box-item-l {
			image {
				width: 88rpx;
				height: 88rpx;
				border-radius: 50%;
				margin-left: 30rpx;
				margin-right: 30rpx;
				z-index: 1;
			}

			.info {
				span {
					color: #171717;
					font-size: 32rpx;
					font-weight: 800;
				}

				text {
					color: #171717;
					font-size: 28rpx;
					font-weight: bold;
					margin-left: 18rpx;
				}
			}

			.address {
				color: #999999;
				font-size: 26rpx;
				font-weight: 500;
			}
		}
	}




	.addWork {
		width: 100%;
		height: 100rpx;
		// background: #F5F5F5;
		position: fixed;
		bottom: 30rpx;
		z-index: 999;

		.addWork-box {
			width: 686rpx;
			height: 100%;
			background-color: #557EFD;
			border-radius: 12rpx;
			color: #FFFFFF;
			font-size: 32rpx;
			font-weight: 800;
		}
	}
</style>
